var app = getApp(); //获取应用实例
const quote = app.globalData.quote;
const mta = quote.mta;
const api = quote.api;
const path = quote.paths;


Page({
    data: {
        path: path,
        practiceData: '',
        loadingHidden: false,
    },

    onLoad: function(options) {
        var that = this;
        // console.log('加载练习记录页面数据', options)

        that.GetUserLearningRecordsNew();

    },
    onReady: function() {
        var that = this;
        // 生命周期函数--监听页面初次渲染完成


    },
    onShow: function() {
        // 生命周期函数--监听页面显示
        var that = this;


    },
    onHide: function() {
        // 生命周期函数--监听页面隐藏

    },
    onUnload: function() {
        // 生命周期函数--监听页面卸载

    },
    // 页面相关事件处理函数--监听用户下拉动作
    onPullDownRefresh: function(params) {
        var that = this;

        //数据加载完后停止刷新
        setTimeout(() => {
            console.log('停止刷新');
            wx.stopPullDownRefresh();
        }, 1000);

    },
    GetUserLearningRecordsNew: function(params) {
        var that = this;

        api.methodGetUserLearningRecordsNew({
            dataDic: {
                OpenId: app.globalData.openId
            },
            success: function(res) {
                if (res.data.code != 0) {
                    wx.showModal({
                        title: '温馨提示',
                        showCancel: false,
                        content: res.data.msg,
                    })
                    return;
                } else {
                    console.log('练习记录数据', res.data.data.MothRecordList)
                    var data = res.data.data.MothRecordList;
                    for (let i = 0; i < data.length; i++) {
                        data[i].Moth = data[i].Moth.replace('-', '年') + '月'
                        for (let j = 0; j < data[i].DataList.length; j++) {
                            data[i].DataList[j].PracticeTime = data[i].DataList[j].PracticeTime.slice(5, 10);
                        }
                    }
                    that.setData({
                        practiceData: data //反转练习记录数据data.reverse()
                    })
                }
            },
            complete: (res) => {
                console.log(res.data);
                that.setData({
                    loadingHidden: true,
                })
            }
        })
    },
    gotoOther: function(params) {
        var that = this;
        console.log(params.currentTarget.dataset);

        wx.navigateTo({
            url: '/' + path.scorePreview + "?QID=" + params.currentTarget.dataset.qid,
            success: function(res) {
                // success
            },
            complete: function() {
                // complete
            }
        })
    },
    imgOnLoad(e) {
        var that = this;

        // console.log('图片加载完成', e);
        const obj = e.currentTarget.dataset.obj;
        if (e.detail.height) {
            that.setData({
                [obj]: true
            })
        }
    }


})